package zcj.stu.generics;

import org.springframework.core.GenericTypeResolver;
import zcj.stu.User;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.Date;

public class GenericsSkill {
    public static void main(String[] args) throws InstantiationException, IllegalAccessException, ClassNotFoundException {
        Type superclass = Dao.class.getGenericSuperclass();
        System.out.println(superclass);
       superclass= superclass instanceof ParameterizedType ? ((ParameterizedType) superclass) : null;
       if(superclass!=null){
           for (Type typeArgument : ((ParameterizedType) superclass).getActualTypeArguments()) {
               System.out.println(typeArgument);
               Class<?> aClass = Class.forName(typeArgument.getTypeName());
               User instance = (User) aClass.newInstance();
               instance.setAge(18);
               instance.setBirthday(new Date());
               System.out.println(instance);
               System.out.println(aClass);
           }
       }
        Class<?> aClass = GenericTypeResolver.resolveTypeArgument(Dao.class, BaseDao.class);
        System.out.println(aClass);
    }
}
